#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
using namespace std;
class Solution {
public:
    int firstMissingPositive(vector<int>& nums) {
        int n = nums.size();
        bool pd = 0;
        for (int i = 0; i < n; i++)
        {
            if (nums[i] == 1)pd = 1;
            if (nums[i] <= 0 || nums[i] > n)
                nums[i] = 1;
        }
        if (!pd)return 1;
        nums.push_back(1);
        for (int i = 0; i < n; i++)
        {
            int sz = abs(nums[i]);
            nums[sz] = -abs(nums[sz]);
        }
        for (int i = 1; i <= n; i++)
        {
            if (nums[i] > 0)return i;
        }
        return n + 1;
    }
};
int main()
{
    Solution sol;
}